package jalus.pojo;

import jalus.utils.HttpUtils;

import java.io.Serializable;
import java.util.Date;

import com.google.appengine.api.datastore.Text;
import com.google.appengine.api.users.User;


/**
 * 评论数据表
 * 
 *
 */
public class Comment  implements Serializable{
	private static final long serialVersionUID = 5383834648763368883L;
	private Long id;
    private Long postId;
    private Date date;
    private User author;
    private Text content;
    private String username;
    private String homepage;
    private String email;
    private String ip;
    public Comment(Long id, Long postId, Date date, User author, Text content, String ip){
    	this.id = id;
    	this.postId = postId;
    	this.date = date;
    	this.author = author;
    	this.content = content;
    	this.ip = ip;
    }
    public Comment(Long id, Long postId, Date date, User author, Text content, String email, String ip) {
    	this.id = id;
    	this.postId = postId;
    	this.date = date;
    	this.author = author;
    	this.content = content;
    	this.email = email;
    	this.ip = ip;
	}
	public Comment() {
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Long getPostId() {
		return postId;
	}
	public void setPost(Long postId) {
		this.postId = postId;
	}
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public User getAuthor() {
		return author;
	}
	public void setAuthor(User author) {
		this.author = author;
	}
	public String getContent() {
		return content.getValue();
	}
	public String getPlainContent() {
		String plain = content.getValue();
		plain = HttpUtils.removeHtmlTag(plain);
		plain = HttpUtils.htmlToText(plain);
		return plain;
	}
	public void setContent(Text content) {
		this.content = content;
	}
	public Date getLast_modify_date() {
		return last_modify_date;
	}
	public void setLast_modify_date(Date last_modify_date) {
		this.last_modify_date = last_modify_date;
	}
	public User getLast_modify_by() {
		return last_modify_by;
	}
	public void setLast_modify_by(User last_modify_by) {
		this.last_modify_by = last_modify_by;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getUsername() {
		if(this.author == null){
			return username;
		}else{
			return this.author.getNickname();
		}
	}
	private Date last_modify_date;
    private User last_modify_by;
	public boolean isAnonymous(){
		return this.author == null;
	}
	public void setHomepage(String homepage) {
		this.homepage = homepage;
	}
	public String getHomepage() {
		return homepage;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getEmail() {
		return email;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	public String getIp() {
		return ip;
	}
}
